/*
  Copyright (c) 2014 Dimitrij Gester

  "Smart RC TX" is free software; you can redistribute it and/or
  modify it under the terms of the GNU Lesser General Public
  License as published by the Free Software Foundation; either
  version 2.1 of the License, or (at your option) any later version.

  "Smart RC TX" is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  Lesser General Public License for more details.

  You should have received a copy of the GNU Lesser General
  Public License along with "Smart RC TX"; if not, write to the
  Free Software Foundation, Inc., 59 Temple Place, Suite 330,
  Boston, MA  02111-1307  USA
*/

package com.codeplex.smartrctx.configurator.main;

import java.util.ArrayList;
import java.util.Set;

import com.codeplex.smartrctx.configurator.communication.BluetoothCommLink;

import rcremote.main.R;


import android.bluetooth.BluetoothDevice;
import android.os.Bundle;
import android.preference.ListPreference;
import android.preference.PreferenceActivity;

public class SettingsActivity extends PreferenceActivity {
    @SuppressWarnings("deprecation")
	@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        addPreferencesFromResource(R.xml.preferences);
        
        ListPreference lp = (ListPreference) findPreference("selectedCommDevice");
        
        try {
			BluetoothCommLink cm = new BluetoothCommLink();
			lp.setEnabled(cm.isEnabled());
			
			Set<BluetoothDevice> devices = cm.getAvailablePorts(); 
			int deviceCount = devices.size();
			ArrayList<String> entries = new ArrayList<String>(deviceCount);
			ArrayList<String> values = new ArrayList<String>(deviceCount);

			for(BluetoothDevice d : devices) {
				entries.add(d.getName());
				values.add(d.getAddress());
			}

			lp.setEntries((String[]) entries.toArray(new String[entries.size()]));
			lp.setEntryValues((String[]) values.toArray(new String[values.size()]));
			
		} catch (Exception e) {
			// no bt adapter
		}
        
        
        
    }
    
    
}